package com.meeting.meet.service.query;

import com.meeting.meet.manager.converter.ReservationAndAgendaDtoConverter;
import com.meeting.meet.manager.dto.ReservationAndAgendaDto;
import com.meeting.meet.manager.dto.ReservationBaseDto;
import com.meeting.meet.persist.qto.GetReservationAndAgendaInfoQto;
import com.meeting.meet.service.ReservationBaseDtoService;
import com.meeting.meet.service.index.entity.GetReservationAndAgendaInfoQtoService;
import com.meeting.meet.service.query.assembler.ReservationAndAgendaDtoDataAssembler;
import com.vs.code.AutoGenerated;
import com.vs.common.util.rpc.pub.PublicInterface;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/** ReservationAndAgendaDto查询方案入口 */
@Service
@AutoGenerated(locked = false, uuid = "9c333606-3b05-3019-911e-53437f16b5ba")
public class ReservationAndAgendaDtoQueryService {
    @AutoGenerated(locked = true)
    @Resource
    private GetReservationAndAgendaInfoQtoService getReservationAndAgendaInfoQtoService;

    @AutoGenerated(locked = true)
    @Resource
    private ReservationAndAgendaDtoConverter reservationAndAgendaDtoConverter;

    @AutoGenerated(locked = true)
    @Resource
    private ReservationAndAgendaDtoDataAssembler reservationAndAgendaDtoDataAssembler;

    @AutoGenerated(locked = true)
    @Resource
    private ReservationBaseDtoService reservationBaseDtoService;

    /** 根据GetReservationAndAgendaInfoQto查询ReservationAndAgendaDto列表,上限500 */
    @PublicInterface(id = "2ff10d16-a56a-4b10-8e55-3113c7feb809", module = "meet")
    @AutoGenerated(locked = false, uuid = "61730cce-c529-38de-828a-8ed0310343f4")
    public List<ReservationAndAgendaDto> getReservationAndAgendaInfo(
            @Valid @NotNull GetReservationAndAgendaInfoQto qto) {
        /** This block is generated by vs, do not modify, start anchor 1 */
        List<Long> ids = getReservationAndAgendaInfoQtoService.query(qto);
        List<ReservationAndAgendaDto> result = toDtoList(ids);
        reservationAndAgendaDtoDataAssembler.assembleData(result);
        /** This block is generated by vs, do not modify, end anchor 1 */
        // 自定义逻辑,e.g. 数据过滤、重组、批量处理等

        /** This block is generated by vs, do not modify, start anchor 2 */
        return result;
        /** This block is generated by vs, do not modify, end anchor 2 */
    }

    /** 将ID列表转换为DtoList */
    @AutoGenerated(locked = true, uuid = "a5d49cb0-85aa-319d-94ee-a72b9c65fb2d")
    private List<ReservationAndAgendaDto> toDtoList(List<Long> ids) {
        List<ReservationBaseDto> baseDtoList = reservationBaseDtoService.getByIds(ids);
        Map<Long, ReservationAndAgendaDto> dtoMap =
                reservationAndAgendaDtoConverter
                        .convertFromReservationBaseDtoToReservationAndAgendaDto(baseDtoList)
                        .stream()
                        .collect(
                                Collectors.toMap(
                                        ReservationAndAgendaDto::getId, Function.identity()));
        return ids.stream()
                .map(id -> dtoMap.get(id))
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}
